import tkinter as tk
from tkinter import filedialog
from PIL import ImageTk, Image

root = tk.Tk()
root.geometry("500x500")
root.title("Image Viewer")


def choose_image():
    img_path = filedialog.askopenfilename(initialdir="images/", title="Select an image",
                                          filetypes=(("JPEG files", "*.jpg"), ("PNG files", "*.png")))
    img = Image.open(img_path)
    img = img.resize((400, 400), Image.LANCZOS)
    img = ImageTk.PhotoImage(img)
    panel.configure(image=img)
    panel.image = img


button = tk.Button(root, text="Select image", command=choose_image)
button.pack(side="bottom", pady=50)

panel = tk.Label(root)
panel.pack(side="top", expand="yes", padx="50", pady="50")

root.mainloop()
